<template>
    <div class="total page">
        <formHeader :title="typeTitle[type]" wColor></formHeader>
        <div class="con">
            <cube-scroll
                    @pulling-down="pullDownRefresh"
                    @pulling-up="pullUpLoad"
                    ref="scroll"
                    :options="options"
                    :data="records"
                    :refreshDelay="20"
            >

                <totalDetail
                        v-for="(item,index) in records"
                        :key="index"
                        :info="item.info"
                        :time="item.time"
                        :amount="item.amount"
                        :bus="item.bus"
                        :type="'earn'"
                ></totalDetail>
            </cube-scroll>
            <!--            <totalDetail-->
            <!--                    v-for="(item,index) in records"-->
            <!--                    :key="index"-->
            <!--                    :info="item.info"-->
            <!--                    :time="parseTime(item.time)"-->
            <!--                    :amount="item.amount"-->
            <!--            ></totalDetail>-->
        </div>
    </div>
</template>

<script>
    import totalDetail from '@/components/totalDetail'
    import formHeader from '@/components/form-header'
    import {record} from "../../api/account"
    import {parseTime} from "../../common/js/time"
    import {mapState} from 'vuex'
    import {getMyEarn} from '@/api/account'
    export default {
        name : "index",
        components:{totalDetail,formHeader},
        computed: {
            ...mapState({
                "userId":state=>state.user.user.userId
            })
        },
        activated(){
            this.type = this.$route.query.type
            this.pullDownRefresh()
        },
        methods:{
            getMyEarn(){
                getMyEarn(this.type,this.page).then(res=>{
                    this.records = this.records.concat(res.data)
                    this.page  = this.page + 1
                })
            },
            pullDownRefresh() {
                this.page = 1
                this.records = []
                this.getMyEarn()
            },
            pullUpLoad() {
                this.getMyEarn()
            }

        },
        data() {
            return {
                type:0,
                typeTitle:['代理有利','分享有利','换购有利','','','','','','店铺有利','服务有利'],
                page: 1,
                options: {
                    pullDownRefresh: {
                        txt: ' '
                    },
                    pullUpLoad: true
                },
                records: []
            }
        }
    }
</script>

<style scoped lang="stylus">
    .total
        background-color $page-bg
        .con
            overflow:auto
            margin-top 46px
            background-color #fff
            height 100%
            /deep/.cube-scroll-content
                padding-bottom 68px

</style>